package lanou.autohome.recommend.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import lanou.autohome.R;
import lanou.autohome.basetool.NetTool;
import lanou.autohome.recommend.beans.QuotationBean;

/**
 * Created by dllo on 16/8/20.
 */
public class QuotationAdapter extends BaseAdapter{

    private Context context;
    private QuotationBean quotationBean;

    public QuotationAdapter(Context context) {
        this.context = context;
    }

    public void setQuotationBean(QuotationBean quotationBean) {
        this.quotationBean = quotationBean;
    }

    @Override
    public int getCount() {
        return quotationBean != null ? quotationBean.getResult().getNewslist().size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_recommend_quotation , null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder)convertView.getTag();
        }

        QuotationBean.ResultBean.NewslistBean bean = quotationBean.getResult().getNewslist().get(position);
        viewHolder.time.setText(bean.getTime());
        viewHolder.title.setText(bean.getTitle());

        NetTool netTool = new NetTool();
        netTool.getImage(bean.getSmallpic() , viewHolder.smallpic);

        return convertView;
    }

    public class ViewHolder{
        ImageView smallpic;
        TextView title;
        TextView time;
        public ViewHolder(View convertView){
            smallpic = (ImageView) convertView.findViewById(R.id.smallpic_recommend_quotation_item);
            title = (TextView) convertView.findViewById(R.id.title_recommend_quotation_item);
            time = (TextView) convertView.findViewById(R.id.time_recommend_quotation_item);
        }

    }

}
